;(function(){
  'use strict';
  angular.module('controllers.oldOMDisplay.upayQM')
  .controller('tradeStatisticsCtrl', tradeStatisticsCtrl);

  function tradeStatisticsCtrl($scope,COREDATA,UpayTradeStatSelecotor,UpayTradeStatQueryParam,UpayTradeStatViewObj){
    $scope.selector = UpayTradeStatSelecotor.setSelector();
    $scope.tradeStat = UpayTradeStatQueryParam.initParam();
    $scope.date = UpayTradeStatQueryParam.initDate();
    $scope.flag = UpayTradeStatQueryParam.initFlag();
    $scope.viewObj = UpayTradeStatViewObj.initViewObj();
    $scope.tradeStatQuery = UpayTradeStatQueryParam.tradeStatQueryFn;
    $scope.exportUrl = COREDATA.FORMPREFIX+'OMdisplay/upayQM/businessQM/tradeStatistics/export';
    $scope.resetParam = function(){
      $scope.tradeStat = UpayTradeStatQueryParam.initParam();
      $scope.date = UpayTradeStatQueryParam.initDate();
      $scope.flag = UpayTradeStatQueryParam.initFlag();
      $scope.viewObj = UpayTradeStatViewObj.initViewObj();
    };

    $scope.$watch('tradeStat.timeType',function(n,o){
      if(n === o) return;
      $scope.date = UpayTradeStatQueryParam.initDate();
  	},true);

  	$scope.$watch('tradeStat.agencyType',function(n,o){
      if(n === o) return;
      $scope.selector = UpayTradeStatSelecotor.setSelector(n.code);
  	}); 
  }
  
  tradeStatisticsCtrl.$inject = ['$scope','COREDATA','UpayTradeStatSelecotor','UpayTradeStatQueryParam','UpayTradeStatViewObj'];
})();